package com.qj.sys.event;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.event.TransactionalEventListener;

/**
 * @author dlw
 * @date 2025-06-03 16:18
 */
@Service
@Slf4j
public class PersonEventListener {
    @TransactionalEventListener(fallbackExecution = true)
    public void listenCreateEvent(PersonChangeEvent personChangeEvent) {
        switch (personChangeEvent.getOperateType()) {
            case "create":
                // 自定义监听后需要执行的逻辑
                // 可以加些后续操作，例如添加缓存、更新缓存等
                log.info("创建Person对象：{}", JSON.toJSONString(personChangeEvent.getPerson()));
                break;
            case "update":
                log.info("更新Person对象：{}", JSON.toJSONString(personChangeEvent.getPerson()));
                break;
            default:
                break;
        }
    }
}
